import React from 'react';
import init from './init.js';
import commandsModule from './commandsModule.js';
import toolbarModule from './toolbarModule.js';
import { version } from '../package.json';
import { utils } from '@ohif/core';
import loadLocales from './loadLocales';
import OHIFCornerstoneViewport from './OHIFCornerstoneViewport';

// const OHIFCornerstoneViewport = utils.asyncComponent(React.lazy(() => import('./OHIFCornerstoneViewport')));

/**
 *
 */
export default {
  /**
   * Only required property. Should be a unique value across all extensions.
   */
  id: 'cornerstone',
  version,

  /**
   *
   *
   * @param {object} [configuration={}]
   * @param {object|array} [configuration.csToolsConfig] - Passed directly to `initCornerstoneTools`
   */
  preRegistration({ servicesManager, configuration = {} }) {
    init({ servicesManager, configuration });
  },
  getViewportModule({ commandsManager, api }) {
    const ExtendedOHIFCornerstoneViewport = props => {
      const onNewImageHandler = jumpData => {
        // commandsManager.runCommand('jumpToImage', jumpData);
      };
      const { useSynchronizerContext } = api.hooks;
      return (
        <OHIFCornerstoneViewport {...props} onNewImage={onNewImageHandler} customProps={{ useSynchronizerContext }} />
      );
    };

    return ExtendedOHIFCornerstoneViewport;
  },
  getToolbarModule() {
    return toolbarModule;
  },
  getCommandsModule({ servicesManager }) {
    return commandsModule({ servicesManager });
  },
};

loadLocales();
